package salesReceiptTransaction;

import java.util.Date;

import classification.CommissionClassification;

import database.PayrollDatabase;

import addEmployeeTransaction.Employee;

import main.Transaction;

public class SalesReceiptTransaction extends Transaction {
	private Date date;
	private double saleAmount;
	private int empId;

	public SalesReceiptTransaction(Date time, double saleAmount, int empId, PayrollDatabase database) {
		super(database);
		
		this.date = time;
		this.saleAmount = saleAmount;
		this.empId = empId;
	}

	@Override
	public void execute() throws Exception {
		Employee e = database.getEmployee(empId);
		
		if (e != null) {
			CommissionClassification hc = (CommissionClassification) e
					.getClassification();

			if (hc != null) {
				hc.addSalesReceipt(new SalesReceipt(date, saleAmount));
			} else {
				throw new Exception("Tried to add sales receipt to"
						+ "non-commissioned employee");
			}
		} else
			throw new Exception("No such employee.");

	}
}
